import time

from selenium.webdriver.common.by import By

from xinan_ui.proxy.base_page import PageHandle
from xinan_ui.tools.read_yml_xn import ReadYaml

data_eles = ReadYaml(r'D:\testLi\PythonWork\xinan_ui\config\jdzapp.yml').read_yaml()['反弹买入模块']

class Ftmr(PageHandle):

    def __init__(self,driver):
        self.driver=driver
        super().__init__(self.driver)

    def ftmr(self,code):
        #点击反弹买入入口
        self.click_button(data_eles[0]['反弹买入入口'])
        time.sleep(2)
        #选择证券按钮
        self.click_button(data_eles[1]['选择证券按钮'])
        time.sleep(1)
        #点击代码输入框
        self.click_button(data_eles[2]['代码输入框'])
        time.sleep(1)
        #输入代码
        self.input_element(data_eles[2]['代码输入框'],code)
        time.sleep(1)
        #选择目标代码
        self.click_button(data_eles[3]['选择目标代码'])
        time.sleep(1)
        #输入监控价格
        self.click_button(data_eles[4]['监控价输入框'])
        time.sleep(2)

        # self.input_element(data_eles[4]['监控价输入框'],price)
        # time.sleep(1)
        # self.click_button(data_eles[17]['键盘完成按钮'])
        # # time.sleep(1)
        #百分比输入
        # self.click_button(data_eles[6]['百分比下拉选择框'])
        # time.sleep(1)
        # self.click_button(data_eles[7]['差价选择按钮'])
        time.sleep(1)
        self.click_button(data_eles[5]['百分比输入框'])
        time.sleep(1)
        self.driver.find_element(By.XPATH,"""/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[1]/android.view.View[3]/android.view.View/android.view.View[3]""").click()
        time.sleep(1)
        self.click_button(data_eles[17]['键盘完成按钮'])
        time.sleep(1)
        #向上滑动
        self.slide_up()
        time.sleep(1)
        #点击委托数量加号按钮
        self.click_button(data_eles[8]['委托数量加号按钮'])
        time.sleep(1)
        # #点击高级设置开关
        # self.click_button(data_eles[9]['高级设置按钮'])
        # time.sleep(1)
        #点击拐点范围开关
        # self.click_button(data_eles[10]['拐点范围开关'])
        # time.sleep(1)
        #输入拐点值
        # self.input_element(data_eles[11]['拐点输入框'],price)
        # time.sleep(1)
        #向上滑动
        # self.slide_up()
        # time.sleep(1)
        # #打开保底开关
        # self.click_button(data_eles[12]['保底价开关'])
        # time.sleep(1)
        #点击确定按钮
        self.click_button(data_eles[13]['确定按钮'])
        time.sleep(1)
        #点击再次确认提交按钮
        self.click_button(data_eles[14]['确认提交按钮'])
        time.sleep(1)
        #点击前往查看按钮
        data=self.get_text(data_eles[18]['下单成功文案'])
        time.sleep(1)
        self.click_button(data_eles[15]['前往查看按钮'])
        time.sleep(1)
        #返回上一级按钮
        self.click_button(data_eles[16]['返回上一级按钮'])
        time.sleep(1)
        return data
